package com.huatai.datacenter.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huatai.common.util.ObjectUtil;
import com.huatai.common.util.StringUtil;
import com.huatai.datacenter.entity.CodeEntity;
import com.huatai.datacenter.mapper.CodeMapper;
import com.huatai.datacenter.service.CodeService;
import org.springframework.stereotype.Service;

/**
 * @author gusiyi
 * @version 1.0
 * @className CodeServiceImpl
 * @description 描述：
 * @date 2023/6/6 13:03
 */
@Service
public class CodeServiceImpl extends ServiceImpl<CodeMapper, CodeEntity> implements CodeService {

	@Override
	public Page<CodeEntity> getListByType(CodeEntity codeEntity) {
		Integer pageIndex = codeEntity.getPageIndex();
		Integer pageSize = codeEntity.getPageSize();
		if (ObjectUtil.isEmpty(pageIndex) || ObjectUtil.isEmpty(pageSize)){
			pageIndex = 1;
			pageSize = Integer.MAX_VALUE;
		}
		String type = codeEntity.getType();
		Page<CodeEntity> page = new Page<>(pageIndex,pageSize);
		LambdaQueryWrapper<CodeEntity> codeQuery = Wrappers.lambdaQuery();
		codeQuery
			.eq(CodeEntity::getDeleted,false)
			.eq(StringUtil.isNotBlank(codeEntity.getType()),CodeEntity::getType, type)
			.eq(ObjectUtil.isNotEmpty(codeEntity.getParentNum()), CodeEntity::getParentNum,codeEntity.getParentNum());
		return page(page, codeQuery);
	}
}
